#include "dlg_login.h"
#include "ui_dlg_login.h"
#include "lib/sqlmgr.h"
#include <QDebug>
#include <QMessageBox>

Dlg_Login::Dlg_Login(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dlg_Login)
{
    ui->setupUi(this);
}

Dlg_Login::~Dlg_Login()
{
    delete ui;
}

void Dlg_Login::on_button_login_clicked()
{
    //获取登陆界面账号和密码
    QString username = ui->le_user->text();
    QString password = ui->le_password->text();

    qDebug() << "username=" << username << ", password=" << password;

    bool loginFlag = SqlMgr::getInstance()->login(username, password);
    loginFlag = true;

    qDebug() << "是否登陆成功:" << loginFlag;
    if(loginFlag){
        //1：成功 2:失败 0:退出
        setResult(1);
        hide();
        return;
    }
    QMessageBox::warning(this, "登陆提示", "账号或密码错误");

}

void Dlg_Login::on_btn_exit_clicked()
{
    //退出
    setResult(0);
    hide();
}
